<?php

	namespace app\job;

	use app\common\model\goods\record\Token;
	use app\common\model\goods\record\Ohcard;
	use think\Exception;
	use think\Log;
	use think\queue\Job;

	class Product{
		public function token(Job $job, $data){
			if ($job->attempts() > 3){
				$this->failed('token',$data);
				$job->delete();
			}else{
				$jobRaw = json_decode($job->getRawBody(),true);
				$res = Token::log($data, $jobRaw['id']);
				Log::write($res,'debug');
				if($res) $job->delete();
			}
		}

		public function ohcard(Job $job, $data){
			if ($job->attempts() > 3){
				$this->failed('ohcard',$data);
				$job->delete();
			}else{
				$jobRaw = json_decode($job->getRawBody(),true);
				$res = Ohcard::log($data, $jobRaw['id']);
				Log::write($res,'debug');
				if($res) $job->delete();
			}
		}

		public function failed($type, $data){
			Log::write('error:'.$type.' failed,data:'.json_encode($data), 'queue');
		}
	}